package com.ta.gulimall.coupon.config.rabbitmq;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class AutoRabbitConfig {
    @Bean
    public DirectExchange defaultDirectExchange(){
        return new DirectExchange(MqQueueConstant.DEFAULT_DIRECT_EXCHANGE, true, false);
    }


//    /**
//     * 警告队列
//     * @return
//     */
//    @Bean("waringQueue")
//    public Queue waringQueue(){
//        return QueueBuilder.durable(MqQueueConstant.WARING_QUEUE_NAME).build();
//    }

//    /**
//     * 备份交换机绑定警告队列
//     * @return
//     */
//    @Bean
//    public Binding waringQueueBingExchange(){
//        return BindingBuilder.bind(waringQueue()).to(backUpExchange());
//    }


    @Bean
    public Queue orderCancelDelayedQuery(){
        return QueueBuilder.durable(MqQueueConstant.SECKILL_STORE_DELAYED_QUEUE)
                .deadLetterExchange(MqQueueConstant.DEFAULT_DIRECT_EXCHANGE)
                .deadLetterRoutingKey(MqQueueConstant.SECKILL_STORE_QUEUE)
                .build();
    }

    @Bean
    public Binding orderCancelDelayedBinding(){
        return BindingBuilder.bind(orderCancelDelayedQuery())
                .to(defaultDirectExchange())
                .with(MqQueueConstant.SECKILL_STORE_DELAYED_QUEUE);
    }

    @Bean
    public Queue orderCancelQuery(){
        return new Queue(MqQueueConstant.SECKILL_STORE_QUEUE);
    }

    @Bean
    public Binding orderCancelBinding(){
        return BindingBuilder.bind(orderCancelQuery())
                .to(defaultDirectExchange())
                .with(MqQueueConstant.SECKILL_STORE_QUEUE);
    }

}
